package miracle.joker.design.command.demo2;

import java.util.LinkedList;
import java.util.Queue;

public class CommandQueue {
    private Queue<Command> undoQueue = new LinkedList<>();
    private Queue<Command> redoQueue = new LinkedList<>();

    public void pushUndoCommand(Command command) {
        undoQueue.offer(command);
        redoQueue.clear();
    }

    public Command popUndoCommand() {
        if (!undoQueue.isEmpty()) {
            Command command = undoQueue.poll();
            redoQueue.offer(command);
            return command;
        }
        return null;
    }

    public Command popRedoCommand() {
        if (!redoQueue.isEmpty()) {
            Command command = redoQueue.poll();
            undoQueue.offer(command);
            return command;
        }
        return null;
    }
}
